<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/5/24
 * Time: 17:14
 */

namespace App\Base;

use BaseExt\Pagination;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;

class BaseController4Shop extends BaseController {

    public function needToBeLogin()
    {
        header('content-type:application/json;charset=utf8');
        $s = 203;
        $i = "请认证身份";
        $d = "";
        $re = array(
            "s"    => $s,
            "i"    => $i,
            "d"    => $d,
        );
        die(json_encode($re));
    }

    public function needToBeUser()
    {
        $roles = $this->getSessionData("role");
        if (is_array($roles) && in_array("ROLE_USER",$roles)) {
            return $this->getSessionData("id");
        } else {
            $this->needToBeLogin();
        }
    }
}
